using System.Collections;
using System.Collections.Generic;
using System.Data;
using CustomORM.DataAccess;
using NUnit.Framework;
using Rhino.Mocks.Generated;

namespace CustomORM.Tests.CustomORM.DataAccess
{
    [TestFixture]
    public class AdoDataAccessTests
    {
        //[Test] - refactor this
        public void SelectSQL_EnsureCanHitDataBaseAndReturnFilledDataTable()
        {
            string ConnectionString = "some connection string";
            var sqlServerDataAccess = new AdoDataAccess(ConnectionString, "FAKE");
            
            //assuming that there is always one record in customer table
            var dataTable = sqlServerDataAccess.SelectSQL("select top 1 * from CUSTOMER");

            string customerLastName = null;
            using (DataTableReader dr = dataTable.CreateDataReader())
            {
                if (dr.Read())
                {
                    customerLastName = (string)dr["NAME_LAST"];
                }
            }

            //assuming that there is always one record in customer table
            Assert.That(!string.IsNullOrEmpty(customerLastName));
        }

        public void SelectSQL_TakesSqlWithParemeters_ExecutesCommandAppropriately()
        {
            string ConnectionString = "some connection string";
            var sqlServerDataAccess = new AdoDataAccess(ConnectionString, "FAKE");

            var parameters = new Dictionary<string, object>();
            parameters.Add("customer_id", 7);

            var dataTable = sqlServerDataAccess.SelectSQL("select customer_id, customer_name from CUSTOMER where customer_id = @customer", parameters);

            string customerLastName = null;
            using (DataTableReader dr = dataTable.CreateDataReader())
            {
                if (dr.Read())
                {
                    customerLastName = (string)dr["NAME_LAST"];
                }
            }

            //assuming that there is always one record in customer table
            Assert.That(!string.IsNullOrEmpty(customerLastName));
        }

        public void InsertUpdateRow_If()
        {
            
        }
    }
}